package com.learnboy.beanregister;

import com.alibaba.druid.sql.PagerUtils;
import com.learnboy.annotation.MyScan;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.MultiValueMap;
import org.springframework.util.ReflectionUtils;

import java.io.File;
import java.lang.reflect.Field;
import java.util.List;

/**
 * MyBeanDefinenRegitster
 * 自定义bean 从注册器
 * @author: cyx_jay
 * @date: 2021/2/2 11:14
 */
public class MyBeanDefinitionRegister implements ImportBeanDefinitionRegistrar {


    @Override
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {
        MultiValueMap<String, Object> myScanProperties = importingClassMetadata.getAllAnnotationAttributes(MyScan.class.getName());
        List<Object> value = myScanProperties.get("value");
        String packageNames = (String) value.get(0);
        Reflections reflections = new Reflections
                (new ConfigurationBuilder().forPackages(packageNames));

        System.out.println(reflections.getAllTypes());


    }
}
